<template>
    <el-card shadow="never" style="border: 0;">
        <yun-form
                :token="true"
                :data="data"
                ref="yunform"
                :columns="eidtColumns">
                <template #default>
                    {:token_field()}
                </template>
            <template #pid="{rows}">
                <el-form-item label="{:__('父级')}:" required>
                    <el-tree-select
                            placeholder="{:__('请选择父级')}"
                            v-model="rows.pid"
                            :data="ruledata"
                            check-strictly
                            :default-expand-all="true"
                            :props='{label:"title",children:"childlist",value:"id"}'
                    >
                    </el-tree-select>
                </el-form-item>
            </template>
            <template #icon="{rows}">
                <el-form-item label="{:__('菜单图标')}:" prop="icon" v-if="rows.ismenu=='1'">
                    <el-input v-model="rows.icon">
                        <template #prepend><i :class="rows.icon"></i></template>
                        <template #append>
                            <el-button size="small" @click="openIconPanel">{:__('选择图标')}</el-button>
                        </template>
                    </el-input>
                </el-form-item>
            </template>
        </yun-form>
    </el-card>
    <check-icon ref="checkicon" @selected="selectIcon"></check-icon>
</template>
<script>
    import form from "@components/Form.js";
    import checkicon from "@components/CheckIcon.js";
    import {TreeIdtoString} from "@util.js";
    function parseActions(row){
        if(parseInt(row.ismenu)===1){
            return row;
        }
        let action=JSON.parse(row.action);
        let title=JSON.parse(row.title);
        let actions={};
        for(let key in action){
            actions[action[key]]=title[key];
        }
        row.actions=actions;
        return row;
    }
    export default{
        components:{'YunForm':form,'CheckIcon':checkicon},
        data:{
            ruledata:TreeIdtoString(Yunqi.data.ruledata),
            data:Yunqi.data.row?parseActions(Yunqi.data.row):{},
            eidtColumns:[
                {field: 'id',edit:'hidden'},
                {field: 'ismenu',title: __('菜单'),edit: {form:'radio',value:'1'},searchList: {'1':__('是'),'0':__('否')}},
                {field: 'pid',title: __('父级'),edit:'slot',rules:'required'},
                {field: 'title', title: __('名称'),visible:function(row){return row.ismenu=='1'},edit:'text'},
                {field: 'controller', title: __('控制器'),edit:'text'},
                {field: 'action', title: __('方法'),edit:'text',visible:function(row){
                    return row.ismenu=='1';
                }},
                {
                    field: 'actions',
                    title: __('方法'),
                    edit: {
                        form:'fieldlist',
                        label:[__('方法名'),__('功能描述')],
                        value:{index:__('查看'),add:__('添加'),edit:__('编辑'),multi:__('更新'),del:__('删除'),import:__('导入'),download:__('下载'),recyclebin:__('回收站')}
                    },
                    visible:function(row){
                        return row.ismenu=='0';
                    },
                },
                {field: 'menutype', title: __('类型'),visible:function(row){return row.ismenu=='1'},edit:{form:'radio',value:'tab'},searchList: Yunqi.data.menutypeList},
                {field: 'icon', title: __('图标'),edit: {form:'slot',value: 'fa fa-th-large'}},
                {field: 'extend', title: __('扩展属性'),visible:function(row){return row.ismenu=='1'},edit: {form:'input',type:'textarea',placeholder:'请输入菜单的扩展属性，格式为json'}},
                {field: 'weigh', title: __('权重'),visible:function(row){return row.ismenu=='1'},edit:(Yunqi.config.action=='edit')?'number':false},
                {field: 'status', title: __('状态'),visible:function(row){return row.ismenu=='1'},edit: {form:'radio',value:'normal'},searchList: {'normal': __('正常'),'hidden': __('隐藏')}}
            ],
            pageinit:false
        },
        methods: {
            openIconPanel:function (){
                this.$refs.checkicon.open();
            },
            selectIcon:function (i){
                this.$refs.yunform.form_.data.icon=i;
            }
        }
    }
</script>
<style>

</style>